package com.yuange.promethues.controller;

import com.yuange.promethues.common.*;
import com.yuange.promethues.service.Yarn3_1_3Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClusterMetricController {

    @Autowired
    Yarn3_1_3Service yarn3_1_3Service;

    @RequestMapping(value = "/metrics/prdClusterMetric",produces = "text/plain")
    public String getRuiboClusterMetric(){
        //发送HTTP请求获取Yarn数据
        String yarnMetrics = yarn3_1_3Service.getYarnSchedulerMetrics(PrdMetricsInfo.CLUSTER_URL_YARN_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_YARN_YUANGE, PrdMetricsInfo.CLUSTER_SCHEDULER_IMPL,
                PrdMetricsInfo.CLUSTER_NAME_YUANGE);

        //发送HTTP请求获取Yarn数据
        yarnMetrics = yarnMetrics + yarn3_1_3Service.getYarnClusterMetrics(PrdMetricsInfo.CLUSTER_URL_YARN_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_YARN_YUANGE, PrdMetricsInfo.CLUSTER_METRICS_IMPL,
                PrdMetricsInfo.CLUSTER_NAME_YUANGE);

        //发送HTTP请求获取NameNodeJMX数据
        yarnMetrics = yarnMetrics + yarn3_1_3Service.getNameNodeJMX(PrdMetricsInfo.CLUSTER_URL_NAMENODE_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_NAMENODE_YUANGE, PrdMetricsInfo.CLUSTER_JMX_IMPL,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGE);

        //发送HTTP请求获取HiveServer2JMX数据
        yarnMetrics = yarnMetrics + yarn3_1_3Service.getHiveServer2JMX(PrdMetricsInfo.CLUSTER_URL_HIVESERVER2_YUANGE212,
                PrdMetricsInfo.CLUSTER_PORT_HIVESERVER2_YUANGE, PrdMetricsInfo.CLUSTER_JMX_IMPL,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGE);

        //发送HTTP请求获取DataNodeJMX数据
        yarnMetrics = yarnMetrics + yarn3_1_3Service.getDataNodeJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_YUANGE, PrdMetricsInfo.CLUSTER_JMX_IMPL,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getDataNodeJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE203,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_YUANGE, PrdMetricsInfo.CLUSTER_JMX_IMPL,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getDataNodeJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE204,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_YUANGE, PrdMetricsInfo.CLUSTER_JMX_IMPL,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGE);

        //telnet方式查看IP端口是否存活
        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_HIVEMETASTORESERVER_YUANGE215,
                PrdMetricsInfo.CLUSTER_PORT_HIVEMETASTORESERVER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_HIVEMETASTORESERVER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_HIVESERVER2_YUANGE212,
                PrdMetricsInfo.CLUSTER_PORT_HIVESERVER2_SOCKET_YUANGE, PrdMetricsInfo.COMPONENT_NAME_HIVESERVER2,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_NAMENODE_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_NAMENODE_YUANGE, PrdMetricsInfo.COMPONENT_NAME_NAMENODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_NAMENODE_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_NAMENODE_SOCKET_YUANGE, PrdMetricsInfo.COMPONENT_NAME_NAMENODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_NODEMANAGER_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_NODEMANAGER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_NODEMANAGER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_NODEMANAGER_YUANGE203,
                PrdMetricsInfo.CLUSTER_PORT_NODEMANAGER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_NODEMANAGER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_NODEMANAGER_YUANGE204,
                PrdMetricsInfo.CLUSTER_PORT_NODEMANAGER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_NODEMANAGER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_JOBHISTORY_SERVER_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_JOBHISTORY_SERVER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_JOBHISTORY_SERVER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_RESOURCEMANAGER_YUANGE203,
                PrdMetricsInfo.CLUSTER_PORT_RESOURCEMANAGER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_RESOURCEMANAGER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_JOURNALNODE_YUANGE205,
                PrdMetricsInfo.CLUSTER_PORT_JOURNALNODE_YUANGE, PrdMetricsInfo.COMPONENT_NAME_JOURNALNODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_JOURNALNODE_YUANGE212,
                PrdMetricsInfo.CLUSTER_PORT_JOURNALNODE_YUANGE, PrdMetricsInfo.COMPONENT_NAME_JOURNALNODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_JOURNALNODE_YUANGE215,
                PrdMetricsInfo.CLUSTER_PORT_JOURNALNODE_YUANGE, PrdMetricsInfo.COMPONENT_NAME_JOURNALNODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_SOCKET_YUANGE, PrdMetricsInfo.COMPONENT_NAME_DATANODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE203,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_SOCKET_YUANGE, PrdMetricsInfo.COMPONENT_NAME_DATANODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_DATANODE_YUANGE204,
                PrdMetricsInfo.CLUSTER_PORT_DATANODE_SOCKET_YUANGE, PrdMetricsInfo.COMPONENT_NAME_DATANODE,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_ZOOKEEPER_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_ZOOKEEPER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_ZOOKEEPER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_ZOOKEEPER_YUANGE212,
                PrdMetricsInfo.CLUSTER_PORT_ZOOKEEPER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_ZOOKEEPER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_ZOOKEEPER_YUANGE215,
                PrdMetricsInfo.CLUSTER_PORT_ZOOKEEPER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_ZOOKEEPER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_SPARKHISTORYSERVER_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_SPARKHISTORYSERVER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_SPARKHISTORYSERVER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_ZEPPELIN_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_ZEPPELIN_YUANGE, PrdMetricsInfo.COMPONENT_NAME_ZEPPELIN,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_AZKABAN_SERVER_YUANGE,
                PrdMetricsInfo.CLUSTER_PORT_AZKABAN_SERVER_YUANGE, PrdMetricsInfo.COMPONENT_NAME_AZKABAN_SERVER,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_AZKABAN_EXECUTOR_YUANGE201,
                PrdMetricsInfo.CLUSTER_PORT_AZKABAN_EXECUTOR_YUANGE, PrdMetricsInfo.COMPONENT_NAME_AZKABAN_EXECUTOR,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_AZKABAN_EXECUTOR_YUANGE203,
                PrdMetricsInfo.CLUSTER_PORT_AZKABAN_EXECUTOR_YUANGE, PrdMetricsInfo.COMPONENT_NAME_AZKABAN_EXECUTOR,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        yarnMetrics = yarnMetrics + yarn3_1_3Service.getTelnetJMX(PrdMetricsInfo.CLUSTER_URL_AZKABAN_EXECUTOR_YUANGE204,
                PrdMetricsInfo.CLUSTER_PORT_AZKABAN_EXECUTOR_YUANGE, PrdMetricsInfo.COMPONENT_NAME_AZKABAN_EXECUTOR,
                PrdMetricsInfo.CLUSTER_TYPE_NAME_YUANGEACTIVE);

        return yarnMetrics;
    }

}
